<?php
session_start();

if (!session_is_registered(myusername)) {
        header("Location: index.php");
}

?>

<?php //TODO:  The query string can be a phone number or an "EQN"?>
<form id="metaQueryForm" action="#" method="GET">
Phone Number: <input type="text" id="metaQueryString" maxlength="15"/>
<input title="Query Submit" rel="Enter a phone number here" class="metaQuerySubmit" type="button" id="metaQuerySubmit" value="query"/>
<input title="Debug" rel="This runs the debug" class="debug" type="checkbox" id="debug"/>
</form>
<br/>
<br/>
<div id="queryResults">

</div>
<script type="text/javascript">

		/*var debugTips = new Tips('.debug');
		debugTips.addEvent('show', function(tip, el){
				tip.fade('in');
			});

		var metaQuerySubmitTips = new Tips('.metaQuerySubmit');
		metaQuerySubmitTips.addEvent('show', function(tip, el){
				tip.fade('in');
			});
		*/
		$('metaQueryForm').addEvent('submit', function(e){
                	if($('metaQueryString').value != ""){
                        	var url = 'metaswitch/meta_query.php?';
                        	url=url+'queryString='+$('metaQueryString').value;
                        	if ($('debug').checked) {
					url=url+'&debug=True';
				}
				else {
					url=url+'&debug=False';
				}
                        	url=url+'&nocache='+Math.random();
                        	/*MochaUI.updateContent({
                                	'element': $('panel1'),
                                	'loadMethod': 'xhr',
                                	'url': url,
					'title': 'Meta Query Results',
                                	'padding': { top: 8, right: 8, bottom: 8, left: 8 }
                        	});*/
				var myRequest = new Request({
							method: 'get',
							url: url,
							onSuccess: function(response){
									$('queryResults').innerHTML = response;
								}
						});
				myRequest.send();
                        	//showSpinner();
                	}
        	});

		$('metaQuerySubmit').addEvent('click', function(e){
                	if($('metaQueryString').value != ""){
                        	var url = 'metaswitch/meta_query.php?';
                        	url=url+'queryString='+$('metaQueryString').value;
                        	if ($('debug').checked) {
					url=url+'&debug=True';
				}
				else {
					url=url+'&debug=False';
				}
                        	url=url+'&nocache='+Math.random();
                        	/*MochaUI.updateContent({
                                	'element': $('panel1'),
                                	'loadMethod': 'xhr',
                                	'url': url,
					'title': 'Meta Query Results',
                                	'padding': { top: 8, right: 8, bottom: 8, left: 8 }
                        	});*/
				var myRequest = new Request({
							method: 'get',
							url: url,
							onSuccess: function(response){
									$('queryResults').innerHTML = response;
								}
						});
				myRequest.send();
                        	//showSpinner();
                	}
        	});

</script>
